package com.marakana.yamba4;

import android.content.Context;
import android.database.Cursor;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.chris.weibo.R;

public class TimeLineAdapter extends SimpleCursorAdapter {

	static final String[] FROM = { DbHelper.C_CREATED_AT, DbHelper.C_USER,
			DbHelper.C_TEXT };
	static final int[] TO = { R.id.textCreatedAt, R.id.textuser, R.id.textText };

	public TimeLineAdapter(Context context, Cursor c) {
		super(context, R.layout.row, c, FROM, TO);
	}

	/**
	 * 这里cursor将绑定到对应的View上
	 */
	@Override
	public void bindView(View row, Context context, Cursor cursor) {
		super.bindView(row, context, cursor);

		// 手工将表示创建时间的时间戳绑定到对应的View
		long timestamp = cursor.getLong(cursor
				.getColumnIndex(DbHelper.C_CREATED_AT));
		TextView textCreatedAt = (TextView) row
				.findViewById(R.id.textCreatedAt);
		textCreatedAt.setText(DateUtils.getRelativeTimeSpanString(timestamp));
	}

}
